package com.smallrig.mall.template.huawei;

import java.util.HashSet;
import java.util.Set;

public class 联通站点 {

    static int[][] sites = new int[][]{{1,1,0,0},{1,1,0,0},{0,0,1,1},{0,0,1,1}};
    static Set<Integer> set = new HashSet<>();

    public static void main(String[] args) {

        int ans = 0;
        for(int i=0;i<sites.length;i++){
            if(set.contains(i)){
                continue;
            }
            dfs(i);
            set.add(i);
            ans++;
        }
        System.out.println(ans);
    }

    public static void dfs(int idx){
        for(int i=0;i<sites.length;i++){
            if(set.contains(i)){
                continue;
            }
            if(i!=idx && sites[idx][i]==1){
                set.add(i);
                dfs(i);
            }
        }
    }

}
